package GamePhysics;

import java.util.LinkedList;
import java.util.Vector;

import utils.myVector;
import GameObjects.*;

public class PhysicsHandler {
	
	private static PhysicsHandler instance= null;
	
	private GameObjectManager objectStorage;
	private myVector tempPos;
	private myVector tempVel;
	private myVector tempAcc;
	private Player tempPlayer;
	private Vector<Enemy> tempEnemyList;
	private Vector<CelestialObject> tempPlanetList;
	private Vector<Bullet> tempBulletList;
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTOR
	private PhysicsHandler(){
		objectStorage = GameObjectManager.getGameObjectManager();
		
		tempPos = new myVector();
		tempVel = new myVector();
		tempAcc = new myVector();
	}

	public static PhysicsHandler getPhysics() {
		if(instance == null)
			instance = new PhysicsHandler();
		return instance;
	}
	
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////// UPDATORS
	///////////////////////////////////////////////////////////////////////////////////////////////PHYSICS
	public void update(float interpolation){
		updatePositions(interpolation);
		updateGravity();
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////POSITIONS
	private void updatePositions(float interpolation){
		tempPlayer = objectStorage.getPlayer();
		tempPos.setVector(tempPlayer.getLocation());
		tempVel.setVector(tempPlayer.getVelocity());
		tempAcc.setVector(tempPlayer.getAcceleration());
		
		tempPos = tempPos.add(
				tempVel.multiplyByConst(interpolation).add(
						tempAcc.multiplyByConst(.05f * interpolation * interpolation)));
				
		tempVel = tempVel.add(
				tempAcc.add(tempPlayer.getMovementDirection().multiplyByConst(tempPlayer.getSpeed())).
				multiplyByConst(interpolation));
		
		tempPlayer.setLocation(tempPos);
		tempPlayer.setVelocity(tempVel);
		
		tempPlayer.setLocalTranslation(tempPlayer.getLocation().x, 0, tempPlayer.getLocation().y);
		
		
		tempEnemyList = objectStorage.getEnemies();
		
		for(Enemy enemy : tempEnemyList){
			
		}
	}

	///////////////////////////////////////////////////////////////////////////////////////////////GRAVITY
	private void updateGravity(){
		
	}
}
